<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if (!session_id()) { session_start(); }

//get some variables

$room_assignments = $_POST['room_assignments'];


do_html_header('UNY-Con Event Room Management', gobig, $uny);

if (!check_valid_user() || $_SESSION['admin'] != 't') {
	echo 'You are not logged in or are not an administrator, please login with the registration tab above';
	print_brs(24);
	do_html_footer();
	exit;
	}

if (isset($_GET['sortkey'])) $sortkey = $_GET['sortkey'];
	else $sortkey = 'event.event_type, event.game_system' ;
if (isset($_GET['sortdir'])) $sortdir = $_GET['sortdir'];
	else $sortdir = 'ASC' ;
if (isset($_GET['searchtype'])) $searchtype = $_GET['searchtype'];
	else $searchtype = 'all' ;
if (isset($_GET['search_key'])) $search_key = $_GET['search_key'];
if (isset($_GET['searchterm'])) $search_string = $_GET['searchterm'];

if (isset($_POST) && !empty($_POST)) $searchtype = search ;
if (isset($_POST['search_key']) && !empty($_POST['search_key'])) $search_key = $_POST['search_key'];
if (isset($_POST['search_string']) && !empty($_POST['search_string'])) {
	if ($_POST['search_key'] == 'event.event_title' || $_POST['search_key'] == 'event.event_type' || $_POST['search_key'] == 'event.game_system') {
		$search_string = '%'.$_POST['search_string'].'%' ;
		} else {
		$search_string = $_POST['search_string'] ;
		}
	} else {
	$search_string = '%' ;
	}	
	
if (isset($room_assignments)) {
	while ($element = each($room_assignments)) {
		list($timeslot,$event_id) = explode(".", $element['key']);
		$room = $element['value'];
		if ($room != '') update_event_room($room, $timeslot, $event_id);
		unset($room, $timeslot, $event_id);
		}
	}

	print_timeslot_search_form();
@$room_menu = create_room_menu($assigned_room);
print_room_assignment_table(get_event_list($searchtype, $search_key, $search_string, $sortkey, $sortdir), $room_menu);


do_html_footer(no_news);